<template>
  <div class="register" :style="'background-image:url('+ Background +');'">
    <div class="item1">
      <div><img src="../../assets/images/logo.png" /></div>
      <div class="title">SAAS平台</div>
      <div class="info">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;宁波杉工智能安全科技股份有限公司建于2004年，是在哈尔滨工业大学及宁波市政府的支持下成立的国家级高新技术企业，长期从事智能传感器网络、结构健康监测系统设计、
        咨询和集成实施、交通基础设施养护管理系统开发等方面的研究和工程应用工作，在结构健康监测系统平台软件开发等方面有着丰富的经验与成功的案例，同时也多次参与结构监测、物联网技术等课题研究，取得了丰硕的研究成果。
        被评为宁波市企业技术工程中心、宁波市院士工作站。其中拥有硕士、博士学位的占研发人员的40%，是一支经验丰富并具有持续创造力的团队。
      </div>
    </div>
    <div class="item2">
      <el-form ref="form" class="register-form" :model="form" :rules="rules">
        <div class="register-form-title">
          <div class="f1">注册</div>
          <div class="f2">
            <router-link to="/login">已有账号？点此登录
            </router-link>
          </div>
        </div>
        <el-form-item label="账号" prop="account">
          <el-input v-model="form.account" placeholder="账号"></el-input>
        </el-form-item>
        <el-form-item label="用户名" prop="name">
          <el-input v-model="form.name" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="邮箱"></el-input>
        </el-form-item>
        <el-form-item label="公司" prop="fullname">
          <el-input v-model="form.fullname" placeholder="公司"></el-input>
        </el-form-item>
        <el-form-item label="公司类型">
          <el-select v-model="form.companyType" placeholder="请选择">
            <el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="公司区域">
          <el-select v-model="form.companyRegion" placeholder="请选择">
            <el-option v-for="item in regions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="register-btn">
          <el-button style="width: 100%" type="primary" @click="onSubmit" :disabled="btnDisabled">立 即 注 册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { register } from '@/api/register'
import { getByCode } from '@/api/system/dict'
import Background from '@/assets/images/background.png'

export default {
  data() {
    return {
      Background: Background,
      form: {
        account: '',
        name: '',
        email: '',
        fullname: '',
        companyType: '',
        companyRegion: ''
      },
      btnDisabled: false,
      types: [],
      regions: [],
      rules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' },
          { max: 32, message: '最大32字符', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { max: 20, message: '最大20字符', trigger: 'blur' }
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ],
        fullname: [
          { required: true, message: '请输入公司名称', trigger: 'blur' },
          { max: 32, message: '最大32字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.loadTypes();
    this.loadRegions();
  },
  methods: {
    onSubmit() {
      this.btnDisabled = true;
      this.$refs['form'].validate((valid) => {
        if (valid) {
          register(this.form).then(response => {
            this.$notify({
              title: '注册成功,请前往邮箱激活',
              type: 'success',
              duration: 1500
            })
          }).catch((response) => {
            this.btnDisabled = false;
          })
        } else {
          this.btnDisabled = false;
        }
      });
    },
    loadTypes() {
      var arr = [];
      getByCode('companyType').then(res => {
        var data = res.data;
        for (var i in data) {
          arr.push({ 'value': data[i].code, 'label': data[i].name });
        }
      })
      this.types = arr;
    },
    loadRegions() {
      var arr = [];
      getByCode('companyRegion').then(res => {
        var data = res.data;
        for (var i in data) {
          arr.push({ 'value': data[i].code, 'label': data[i].name });
        }
      })
      this.regions = arr;
    }
  },
}
</script>

<style rel="stylesheet/scss" lang="scss">
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-size: cover;

  > div {
    -webkit-box-shadow: 0 0 11px rgba(0, 0, 0, 0.5);
  }

  .item1 {
    border-radius: 10px;
    width: 540px;
    height: 700px;
    background-color: rgb(75 90 111);
    .title {
      text-align: center;
      color: white;
      font-weight: bold;
      font-size: 50px;
      font-family: 微软雅黑;
      padding: 10px 25px 5px 25px;
    }
    .info {
      color: white;
      padding: 0px 25px 5px 25px;
      line-height: 22px;
    }

    img {
      width: 472px;
      margin-top: 30px;
    }
  }

  .item2 {
    border-radius: 10px;
    width: 540px;
    height: 700px;
    background-color: #ffffff;
  }

  .register-form {
    border-radius: 6px;
    background: #fff;
    width: 474px;
    padding: 75px 25px 5px 80px;
  }

  .register-form .register-form-title {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    color: #707070;
    .f1 {
      font-weight: bold;
      margin-left: 35px;
      font-size: 24px;
    }
    .f2 {
      line-height: 24px;
      margin-top: 6px;
      font-size: 14px;
    }
  }

  .register-form .el-form-item__label {
    width: 80px;
    margin-top: 10px;
  }
  .register-form .el-form-item__content {
    margin-left: 80px;
    margin-top: 10px;
  }
  .register-form .register-btn {
    width: 100%;
    text-align: center;
  }
  .register-form .register-btn .el-form-item__content {
    margin-left: 0px;
  }
}
</style>
